package org.zeapp.opencloud.framework.preference;

/**
 * All Preference provider must implements this interface. Allows to retrieve
 * and store preference data.
 * 
 * @author Amphiprion
 * 
 */
public interface Preference {
	/**
	 * Put the given preference.
	 * 
	 * @param key
	 *            the preference key
	 * @param value
	 *            the preference value
	 */
	void set(String key, String value);

	/**
	 * Put the given integer preference.
	 * 
	 * @param key
	 *            the preference key
	 * @param value
	 *            the preference value
	 */
	void set(String key, int value);

	/**
	 * Retrieve the given preference value
	 * 
	 * @param key
	 *            the preference key
	 * @return the preference value. Null if the key does not exists.
	 */
	String get(String key);

	/**
	 * Retrieve the given preference value
	 * 
	 * @param key
	 *            the preference key
	 * @param defaultValue
	 *            the value to return if the key does not exists
	 * @return the preference value.
	 */
	String get(String key, String defaultValue);

	/**
	 * Retrieve the given preference integer value
	 * 
	 * @param key
	 *            the preference key
	 * @param defaultValue
	 *            the value to return if the key does not exists or if the value
	 *            is not an integer
	 * @return the preference value.
	 */
	int getInt(String key, int defaultValue);

	/**
	 * Persist the preference modifications.
	 * 
	 * @return true if the commit succeed
	 */
	boolean commit();
}
